home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Languages
/
CGI shell
/
Pocket 6.4
/
Extensions
/
Misc
< prev
Wrap
Text File
|
1993-12-26
|
4KB
|
105 lines
( Misc extras for Pocket Forth 0.6.3 or 1.6.3 ) decimal
0 28 +md !
\ additional stack words
: SP! ( -- ) s0@ ,$ 2C5E ; ( move.l [ps]+,ps ) ( reset pstack )
: NIP ( n1 n2 -- n2 ) ,$ 3C9E ; MACRO ( move [ps]+,[ps] )
: TUCK ( n1 n2 -- n2 n1 n2 ) swap over ;
: 4+ ( n -- n+4 ) ,$ 5856 ; MACRO ( addq #4,[ps] )
\ compiled strings
: EVEN ( n -- n' ) \ dup 2 mod + ; ( round up to even number )
,$ 5256 ,$ 256 ,$ fffe ;
: ," ( -- ) ( compile a quoted string from input stream )
34 word here c@ 1+ even allot ; IMMEDIATE
\ return stack words: Used for extended toolbox support.
: RP! ( -- ) r0@ ,$ 2E5E ; ( move.l [ps]+,rs ) ( reset rstack )
: 0>R ( rstack: -- 0 ) ,$ 4267 ; MACRO ( clr -[rs] )
: 00>R ( rstack: -- 0 0 ) ,$ 42A7 ; MACRO ( clr.l -[rs] )
: 2R ( -- d ) ( rstack: d -- d )
,$ 2D17 ; MACRO ( move.l [rs],-[ps] )
\ Some Mac interface stuff:
\ Call an alert from an _existing_ ALRT resource.
\ Make it with ResEdit and add it to (a copy of) Pocket Forth.
: .ALERT ( resource.ID -- dismissing.item.number )
0>r >r 00>r ,$ a985 r> ; ( _Alert )
\ Get the handle of an _existing_ resource.
: REZ ( id type -- dhandle true or false )
00>r 2>r >r ,$ A9A0 2r> ( _GetResource )
2dup IF -1 ELSE drop THEN ; ( leave error flag )
\ Run a subroutine from a handle to it.
\ Nothing is saved, so make sure your external code does.
\ See machine language section of Pocket Forth manual.
: RUN ( dhandle -- )
dl@ ,$ 205E ,$ 4E90 ; ( move.l [ps]+,a0 jsr [a0] )
\ Pick a random number from 0 to n
: SEED ( -- daddr ) ,$ 2d15 126 0 dnegate d+ ;
: TIME ( -- d ) 524 0 dl@ ;
: RANDOMIZE time seed dl! ;
: RANDOM ( n -- n' )
0>r ,$ A861 r> ( _Random )
swap 32768 */ abs ; ( scale to size from stack )
\ Get the main screen's size in pixels.
: SSIZE ( -- h v ) \ access a global (a5) variable
,$ 2d2d ,$ ff8c ; MACRO \ move.l screenBits(a5),-(a6)
\ color testing
: ?COLOR ( -- f ) \ true if color is available and system>6.0.4
,s qd ?gestalt dup IF 2drop 256 < 0= THEN ;
: GDEVICE ( -- dhandle ) \ handle of grafics device
00>r ,$ aa32 2r> ; ( _getGDevice )
: BITS/PIXEL ( -- n ) \ n = bit depth of monitor setting
?color IF
gdevice dl@ 22 s>d d+ \ handle of pixmap
dl@ dl@ 32 s>d d+ l@ \ get the pixsize
ELSE 1 THEN ;
\ Put a character on the clipboard.
: >CLIP ( c -- )
256 * ( move ascii data into byte position )
00>r ,$ A9FC 2r> 2drop ( _ZeroScrap )
00>r 1 0 2>r ,s TEXT 2>r sp@ 2>r ,$ A9FE ( _PutScrap )
2r> + IF beep THEN ; ( beep on error )
: ?DA ( -- flag ) \ true if the Pocket Forth DA is running
0 +md 2@ ( the window's pointer )
108 0 d+ l@ 0< ; ( the windowKind integer<0 if DA kind )
( Display memory in hex )
: H.2 ( n -- ) \ Print a hex number with at least 2 digits.
base @ >r hex dup 16 < IF
0 . 8 emit THEN . r> base ! ;
: A. ( addr -- ) h.2 8 emit ." : " ; \ print formatted addr
: DUMP ( addr len -- ) \ Do a formatted hex dump of memory.
swap dup -16 and swap dup a. ( next lower rounded addr )
over - dup 0 DO space space space LOOP ." |" ( marker )
rot + over cr a. 0 DO ( number of lines )
dup r + c@ h.2 ( print byte value at addr + index )
r 1+ 16 mod 0= IF ( If at end of 16 byte line... )
dup r + 1+ cr a. THEN LOOP ( ...start a new line )
drop cr ;
( Case by Randolph Peters of the University of Pennsylvania )
: CASE 0 ; IMMEDIATE \ Example:
: OF \ : SWITCH ( n -- )
[ ' over literal ] compile \ case
[ ' = literal ] compile \ 0 of ." Off" cr endof
[compile] if ; IMMEDIATE \ 1 of ." On" cr endof
: ENDOF [compile] else ; immediate \ otherwise ." None"
: OTHERWISE ; IMMEDIATE \ endcase ;
: ENDCASE
BEGIN ?dup WHILE [compile] then REPEAT
[ ' drop literal ] compile ; IMMEDIATE
-1 28 +md !
( You have just loaded several utility words.)
( Examine them in the Misc file for more info)